import axios from "axios";
import {nanoid} from "nanoid";

export default {
    namespaced: true,
    actions: {
        addWang(context, value) {
            if (value.name[0] === '王') {
                context.commit('addPerson', value);
            } else {
                console.log("添加的人不姓王！");
            }
        },
        addPersonFromServer(context, value) {
            axios.get('https://api.uixsj.cn/hitokoto/get?type=social').then(resp => {
                context.commit('addPerson', {id: nanoid(), name: resp.data});
            }, err => {
                console.log(err.message);
            });
        },
    },
    mutations: {
        addPerson(state, value) {
            state.people.push(value);
        },
    },
    state: {
        people: [
            {id: '0001', name: '张三'}
        ]
    },
    getters: {}
};